home *** CD-ROM | disk | FTP | other *** search
- PAGE ,132
- TITLE Calculate 10**ST
- IF1
- INCLUDE 87MAC.LIB
- ENDIF
- CODE SEGMENT PUBLIC
- ASSUME CS:CODE,DS:CODE
- PUBLIC TEN_TO_X
- OLD_CW DW ?
- NEW_CW DW ?
- ;-----------------------------------------------;
- ; This routine will take the top element of ;
- ; the 8087 stack, and raise ten to that power ;
- ; Input -- ST0 is X ;
- ; Output -- ST0 is 10**X ;
- ; This routine uses two stack positions plus ;
- ; the parameter, a total of three. ;
- ;------------------------------------------------
- TEN_TO_X PROC NEAR
- ;-----ST0-------;-----ST1-------;---ST2-------
- ; X ; ? ; ?
- FLDL2T ; LOG2(10) ; X ; ?
- FMULP ST1,ST0 ;X LOG2(10) = E ; ? ; ?
- FNSTCW OLD_CW ;---------------;---------------;-------------
- FWAIT ; Get the current status word
- MOV AX,OLD_CW ; Save it
- AND AX, NOT 0C00H ; Set rounding control to
- OR AX, 0400H ; round towards -infinity
- MOV NEW_CW,AX
- FLDCW NEW_CW ;---------------;---------------;-------------
- FLD1 ; 1 ; E ; ?
- FCHS ; -1 ; E ; ?
- FLD ST1 ; E ; -1 ; E
- FRNDINT ; INT(E) = I ; -1 ; E
- FLDCW OLD_CW ; ; ;
- FXCH ST2 ; E ; -1 ; I
- FSUB ST0,ST2 ; E - I = F ; -1 ; I
- FSCALE ; F*2**-1 = F/2 ; -1 ; I
- F2XM1 ;(2**F/2)-1 ; -1 ; I
- FSUBRP ST1,ST0 ; 2**F/2 ; I ; ?
- FMUL ST0 ; 2**F ; I ; ?
- FSCALE ;(2**F)*(2**I) ; I ; ?
- FXCH ST1 ; I ; 2**(I+F) ; ?
- FISTP OLD_CW ; 2**(I+F) ; ? ; ?
- RET ; 10**X ; ? ; ?
- TEN_TO_X ENDP
- CODE ENDS
- END
-